<template>
	<view class="apply-pages" :style="{ background: pageColor }">
		<block v-if="isLoad">
			<view class="apply-form">
				<view class="fill-base radius-16">
					<view @tap.stop="toChooseUser" class="flex-between pl-lg pr-lg b-1px-b">
						<view class="item-text">关联用户</view>
						<view class="item-input flex-1 text">
							<view class="flex-between">
								{{ form.user_id ? form.nickName : '请选择' }}
								<i class="iconfont icon-right ml-sm" style="font-size: 28rpx"
									v-if="edit_base_info && !form.user_id"></i>
							</view>
						</view>
					</view>
					<view class="flex-between pl-lg pr-lg b-1px-b">
						<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>姓名</view>
						<input :disabled="!edit_base_info ? true : false" v-model="form.coach_name" type="text"
							class="item-input flex-1" maxlength="20" :placeholder="rule[0].errorMsg" />
					</view>
					<view class="flex-between pl-lg pr-lg b-1px-b" v-if="configInfo.plugAuth.industrytype == 3">
						<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>职业分类
						</view>
						<view class="flex-1 flex-center"
							v-if="!edit_base_info || (edit_base_info && (![-1,4].includes(coach_status)))">
							<input :disabled="true" v-model="industryInfo.title" class="item-input flex-1" />
						</view>
						<view class="item-input flex-1 text" v-else>
							<picker @change="pickerChange($event, 'industry')" :value="industryIndex"
								:range="industryList" range-key="title">
								<view class="flex-between">
									{{ industryIndex != -1 ? industryList[industryIndex].title : '请选择' }}
									<i class="iconfont icon-right ml-sm" style="font-size: 28rpx"></i>
								</view>
							</picker>
						</view>
					</view>
					<view class="flex-between pl-lg pr-lg b-1px-b">
						<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>性别</view>
						<view class="item-input flex-1 flex-y-center">
							<view @tap.stop="toSetItem(index, 'sex', 'sexList')" class="flex-y-center"
								:class="[{ 'mr-lg': item.id == 0 }]"
								:style="{ color: form.sex == item.id ? primaryColor : '' }"
								v-for="(item, index) in sexList" :key="index"><i class="iconfont icon-xuanze mr-sm"
									:class="[{ 'icon-xuanze-fill': form.sex == item.id }]"></i>{{ item.title }}
							</view>
						</view>
					</view>
					<block v-if="industryInfo.height">
						<view class="flex-between pl-lg pr-lg b-1px-b">
							<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>身高
							</view>
							<view class="flex-1 flex-center">
								<input :disabled="!edit_base_info ? true : false" v-model="form.height" type="number"
									class="item-input flex-1" :placeholder="rule[2].errorMsg" />
								<view class="c-title">cm</view>
							</view>
						</view>
					</block>
					<block v-if="industryInfo.weight">
						<view class="flex-between pl-lg pr-lg b-1px-b">
							<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>体重
							</view>
							<view class="flex-1 flex-center">
								<input :disabled="!edit_base_info ? true : false" v-model="form.weight" type="digit"
									class="item-input flex-1" :placeholder="rule[3].errorMsg" />
								<view class="c-title">kg</view>
							</view>
						</view>
					</block>
					<view class="flex-between ml-lg mr-lg b-1px-b" v-if="industryInfo.birthday">
						<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>生日</view>
						<view class="item-input flex-1 text">
							<picker :disabled="!edit_base_info ? true : false"
								@change="pickerChange($event, 'birthday')" mode="date" :end="endYear"
								:value="form.birthday">
								<view class="flex-between">
									{{ form.birthday || '请选择' }}
									<i class="iconfont icon-right ml-sm" style="font-size: 28rpx"></i>
								</view>
							</picker>
						</view>
					</view>
					<block v-if="form.birthday && industryInfo.constellation">
						<view class="flex-between pl-lg pr-lg b-1px-b">
							<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>星座
							</view>
							<view class="flex-1 flex-center">
								<input :disabled="true" v-model="form.constellation" class="item-input flex-1" />
							</view>
						</view>
					</block>
					<view class="flex-between pl-lg pr-lg b-1px-b">
						<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>手机号</view>
						<input :disabled="!edit_base_info ? true : false" v-model="form.mobile" type="text"
							class="item-input flex-1" maxlength="11" :placeholder="rule[5].errorMsg" />
					</view>
					<view class="flex-between pl-lg pr-lg b-1px-b" v-if="industryInfo.employment_years">
						<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>从业年份
						</view>
						<view class="flex-1 flex-center">
							<input :disabled="!edit_base_info ? true : false" v-model="form.work_time" type="number"
								class="item-input flex-1" :placeholder="rule[6].errorMsg" />
							<view class="c-title">年</view>
						</view>
					</view>
					<view class="flex-between pl-lg pr-lg b-1px-b">
						<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>意向工作城市
						</view>
						<view class="flex-1 flex-center"
							v-if="!edit_base_info || (form.id && !configInfo.agent_update_city)">
							<input :disabled="true" v-model="form.city" class="item-input flex-1" />
						</view>
						<view class="item-input flex-1 text" v-else>
							<picker @change="pickerChange($event, 'city')" :value="cityIndex" :range="cityList"
								range-key="title">
								<view class="flex-between">
									{{ cityIndex != -1 ? cityList[cityIndex].title : '请选择' }}
									<i class="iconfont icon-right ml-sm" style="font-size: 28rpx"></i>
								</view>
							</picker>
						</view>
					</view>
					<view class="flex-between pl-lg pr-lg b-1px-b" v-if="configInfo.plugAuth.career">
						<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>职业类型
						</view>
						<view class="item-input text flex-1">
							<picker @change="pickerChange($event, 'type')" :value="typeIndex" :range="typeList"
								range-key="title">
								<view class="flex-between">
									<view class="max-400 ellipsis">
										{{ typeIndex != -1 ? typeList[typeIndex].title : '请选择' }}
									</view>
									<i class="iconfont icon-right ml-sm" style="font-size: 28rpx"></i>
								</view>
							</picker>
						</view>
					</view>
					<view class="flex-between pl-lg pr-lg b-1px-b"
						v-if="configInfo.plugAuth.industrytype == 3 && industryIndex != -1">
						<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>岗位标签
						</view>
						<view class="item-input text flex-1">
							<picker @change="pickerChange($event,'station')" :value="stationIndex" :range="stationList"
								range-key="title">
								<view class="flex-between">
									{{stationIndex!=-1?stationList[stationIndex].title:'请选择'}}
									<i class="iconfont icon-right ml-sm" style="font-size: 28rpx;"></i>
								</view>
							</picker>
						</view>
					</view>
					<view class="flex-between pl-lg pr-lg b-1px-b">
						<view class="item-text flex-y-center">个性标签</view>
						<view class="item-input text flex-1">
							<picker @change="pickerChange($event,'personality')" :value="personalityIndex"
								:range="personalityList" range-key="title">
								<view class="flex-between">
									{{personalityIndex!=-1?personalityList[personalityIndex].title:'请选择'}}
									<i class="iconfont icon-right ml-sm" style="font-size: 28rpx;"></i>
								</view>
							</picker>
						</view>
					</view>
					<view class="flex-between pl-lg pr-lg b-1px-b"
						v-if="configInfo.plugAuth.store && (store_auth || form.store_name)">
						<view class="item-text">挂靠门店</view>
						<view class="item-input text flex-1">
							<view
								@tap.stop="store_auth ? $util.goUrl({url:`/technician/pages/choose-store?agent=1`}):``"
								class="flex-between">
								<view>{{form.store_name || `请选择`}}</view>
								<i class="iconfont icon-right ml-sm" style="font-size: 28rpx;" v-if="store_auth"></i>
							</view>
						</view>
					</view>
					<block v-if="faree_info.free_fare_bear">
						<view class="flex-between pl-lg pr-lg b-1px-b">
							<view class="item-text" style="height: auto">免出行费半径距离</view>
							<view class="flex-1 flex-center">
								<input :disabled="!edit_base_info ? true : false" v-model="form.free_fare_distance"
									type="digit" class="item-input flex-1" :placeholder="rule[10].errorMsg" />
								<view class="c-title">km</view>
							</view>
						</view>
					</block>
					<view class="flex-between pl-lg pr-lg">
						<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>所在地址
						</view>
						<view class="item-input text flex-1">
							<view @tap.stop="toChooseLocation" class="flex-between">
								<view>{{ form.address || `点击右边图标设置` }}</view>
								<i class="iconfont iconjuli ml-sm" :style="{ color: primaryColor }"></i>
							</view>
						</view>
					</view>
				</view>
				<view class="fill-base mt-md radius-16">
					<view class="flex-between pl-lg pr-lg">
						<view class="item-text flex-y-center" style="width: auto"><i
								class="iconfont icon-required c-warning"></i>{{ $t('action.attendantName') }}简介</view>
						<input :disabled="true" type="text" class="item-input flex-1" />
					</view>
					<textarea :disabled="!edit_base_info ? true : false" v-model="form.text" class="item-textarea pd-lg"
						maxlength="300" :placeholder="rule[12].errorMsg" />
					<view class="text-right pb-lg pr-lg">
						{{ form.text.length > 300 ? 300 : form.text.length }}/300
					</view>
				</view>
				<view class="fill-base mt-md radius-16">
					<view class="flex-between pl-lg pr-lg b-b">
						<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>身份证号
						</view>
						<input :disabled="!edit_base_info ? true : false" v-model="form.id_code" type="text"
							class="item-input flex-1" :placeholder="rule[13].errorMsg" />
					</view>
					<view class="flex-between pl-lg pr-lg">
						<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>真实姓名
						</view>
						<input :disabled="!edit_base_info ? true : false" v-model="form.true_user_name" type="text"
							class="item-input flex-1" maxlength="10" :placeholder="rule[14].errorMsg" />
					</view>
				</view>
				<view class="fill-base mt-md radius-16">
					<view class="flex-between pl-lg pr-lg">
						<view class="item-text tips flex-y-center"><i class="iconfont icon-required c-warning"></i>身份证照片
						</view>
						<view class="item-input flex-1">图片大小不超过10M</view>
					</view>
					<view class="flex-between pl-lg pr-lg pb-md">
						<upload @upload="imgUpload" :imagelist="form.id_card" imgtype="id_card" imgclass="md"
							text="身份证人像面" :imgsize="1" :isEdit="!edit_base_info ? false : true">
						</upload>
						<upload @upload="imgUpload" :imagelist="form.id_card_fan" imgtype="id_card_fan" imgclass="md"
							text="身份证国徽面" :imgsize="1" :isEdit="!edit_base_info ? false : true">
						</upload>
					</view>
					<view class="flex-between pl-lg pr-lg pb-md">
						<upload @upload="imgUpload" :imagelist="form.id_card_people" imgtype="id_card_people"
							imgclass="md" text="手持身份证照片" :imgsize="1" :isEdit="!edit_base_info ? false : true"></upload>
					</view>
				</view>
				<view class="fill-base mt-md radius-16" v-if="industryInfo.qualification">
					<view class="flex-between pl-lg pr-lg">
						<view class="item-text tips flex-y-center"><i class="iconfont icon-required c-warning"></i>资格证书
						</view>
						<view class="item-input flex-1">图片大小不超过10M</view>
					</view>
					<view class="flex-between pl-lg pr-lg pb-md">
						<upload @upload="imgUpload" @del="imgUpload" :imagelist="form.license" imgtype="license"
							text="上传图片" :imgsize="15" :isEdit="!edit_base_info ? false : true">
						</upload>
					</view>
				</view>
				<view class="fill-base mt-md radius-16">
					<view class="flex-between pl-lg pr-lg">
						<view class="item-text tips flex-y-center"><i class="iconfont icon-required c-warning"></i>工作形象照
						</view>
						<view class="item-input flex-1">图片建议尺寸: 750 * 750，大小不超过10M</view>
					</view>
					<view class="flex-between pl-lg pr-lg pb-md">
						<upload @upload="imgUpload" :imagelist="form.work_img" imgtype="work_img" text="上传图片"
							:imgsize="1" :isEdit="!edit_base_info ? false : true">
						</upload>
					</view>
				</view>
				<view class="fill-base mt-md radius-16">
					<view class="flex-between pl-lg pr-lg">
						<view class="item-text tips flex-y-center"><i
								class="iconfont icon-required c-warning"></i>{{$t('action.lifeText')}}
						</view>
						<view class="item-input flex-1">图片建议尺寸: 750 * n，大小不超过10M</view>
					</view>
					<view class="flex-between pl-lg pr-lg pb-md">
						<upload @upload="imgUpload" @del="imgUpload" :imagelist="form.self_img" filetype="picture"
							imgtype="self_img" text="上传图片" :imgsize="9" :isEdit="!edit_base_info ? false : true">
						</upload>
					</view>
				</view>
				<view class="fill-base mt-md radius-16">
					<view class="flex-between pl-lg pr-lg">
						<view class="item-text tips">个人视频介绍</view>
						<view class="item-input flex-1">视频大小不超过50M</view>
					</view>
					<view class="flex-between pl-lg pr-lg pb-md">
						<upload @upload="imgUpload" @del="imgUpload" :imagelist="form.video" filetype="video"
							imgtype="video" text="上传视频" :imgsize="1" :isEdit="!edit_base_info ? false : true">
						</upload>
					</view>
				</view>
				<view class="fill-base mt-md radius-16">
					<view class="flex-between pl-lg pr-lg b-1px-b">
						<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>虚拟订单
						</view>
						<view class="flex-1 flex-center">
							<input :disabled="!edit_base_info ? true : false" v-model="form.order_num" type="number"
								class="item-input flex-1" :placeholder="rule[21].errorMsg" />
							<view class="c-title">单</view>
						</view>
					</view>
					<view class="flex-between pl-lg pr-lg b-1px-b">
						<view class="item-text flex-y-center"><i class="iconfont icon-required c-warning"></i>是否接单
						</view>
						<view class="item-input flex-1 flex-y-center">
							<view @tap.stop="toSetItem(index, 'is_work', 'workList')" class="flex-y-center"
								:class="[{ 'mr-lg': item.id == 1 }]"
								:style="{ color: form.is_work == item.id ? primaryColor : '' }"
								v-for="(item, index) in workList" :key="index"><i class="iconfont mr-sm" :class="[
                    { 'icon-xuanze': form.is_work != item.id },
                    { 'icon-radio-fill': form.is_work == item.id }
                  ]"></i>{{ item.title }}
							</view>
						</view>
					</view>
					<view class="flex-between pd-lg" v-if="form.is_work === 1">
						<view @tap.stop="toShowTime('start_time')" class="item-time flex-center flex-column">
							<view>开始时间</view>
							<view class="mt-sm" :style="{ color: form.start_time ? primaryColor : '#999' }">
								{{ form.start_time || '选择时间' }}
							</view>
						</view>
						<view @tap.stop="toShowTime('end_time')" class="item-time flex-center flex-column b-1px-l">
							<view>结束时间</view>
							<view class="mt-sm" :style="{ color: form.end_time ? primaryColor : '#999' }">
								{{ form | handleStartEndTime(toDay) }}{{ form.end_time || '选择时间' }}
							</view>
						</view>
					</view>
				</view>
				<view @tap.stop="toFddSign" class="fill-base mt-md radius-16"
					v-if=" fdd_agreement && fdd_agreement.hasOwnProperty('viewpdf_url') && edit_base_info ">
					<view class="flex-between pl-lg pr-lg b-1px-b">
						<view class="item-text">电子签约</view>
						<view class="item-input flex-1" :style="{ color: primaryColor }">
							查看签约合同
						</view>
					</view>
				</view>
			</view>

			<view class="space-max-footer"></view>

			<block v-if="!edit_base_info"></block>
			<fix-bottom-button @confirm="submit" :text="[{ text: '确定提交', type: 'confirm' }]" bgColor="#fff" v-else>
			</fix-bottom-button>

			<w-picker :visible.sync="showTime" mode="time" :value="toDayTime" :current="false" :second="false"
				:themeColor="primaryColor" @confirm="onConfirm" ref="time"></w-picker>
		</block>
		<!-- #ifdef MP-WEIXIN -->
		<user-privacy ref="user_privacy" :show="false"></user-privacy>
		<!-- #endif -->
		<!-- #ifdef APP-PLUS -->
		<longbingbing-app-check-auth type="location" ref="app_check_item"
			@confirm="toConfirmChooseLoca"></longbingbing-app-check-auth>
		<!-- #endif -->
	</view>
</template>

<script>
	import $util from "@/utils/index.js"
	import {
		mapState,
		mapActions,
		mapMutations
	} from "vuex"
	export default {
		components: {},
		data() {
			return {
				isLoad: false,
				store_auth: false,
				options: {},
				coach_status: -1,
				edit_base_info: 1,
				industryList: [],
				industryIndex: -1,
				industryInfo: {},
				cityList: [],
				cityIndex: -1,
				typeList: [],
				typeIndex: -1,
				toDay: '',
				toDayTime: '',
				showKey: '',
				showTime: false,
				sexList: [{
					id: 0,
					title: '男'
				}, {
					id: 1,
					title: '女'
				}],
				workList: [{
					id: 1,
					title: '接单'
				}, {
					id: 0,
					title: '休息'
				}],
				fdd_agreement: {},
				faree_info: {},
				form: {
					id: 0,
					admin_id: 0,
					user_id: '',
					nickName: '',
					coach_name: '', //姓名 
					industry_type: '',
					mobile: '', //手机号 
					sex: 0, //性别 
					height: '',
					weight: '',
					birthday: '',
					constellation: '',
					work_time: '', //从业年份 
					city_id: '', // 城市id
					city: '',
					type_id: '',
					store: [], // 门店id
					store_name: '',
					free_fare_distance: '',
					lng: '',
					lat: '',
					address: '', //详细地址 
					text: '', //备注 
					id_code: '', //身份证号
					true_user_name: '', //真实姓名
					id_card: [], //身份证
					id_card_fan: [], // 身份证反面
					id_card_people: [], //手持身份证
					license: [], //资格证书
					work_img: [], // 工作照
					self_img: [], // 生活-照
					city_id: '', // 城市 id
					video: [],
					order_num: 0,
					is_work: 1,
					show_salenum: 0,
					start_time: '00:00',
					end_time: '00:00',
					station_icon: '',
					personality_icon: ''
				},
				rule: [{
						name: "coach_name",
						checkType: "isNotNull",
						errorMsg: "请输入您的姓名",
						regType: 2
					}, {
						name: "industry_type",
						checkType: "isNotNull",
						errorMsg: "请选择职业分类",
					}, {
						name: "height",
						checkType: "isNumber",
						errorMsg: "请输入您的身高",
						regType: 2
					}, {
						name: "weight",
						checkType: "isFloatNum",
						errorMsg: "请输入您的体重",
						regType: 1,
						dotLen: 1,
						maxNum: '',
						unit: 'kg'
					}, {
						name: "birthday",
						checkType: "isNotNull",
						errorMsg: "请选择您的生日",
						regType: 2
					},
					{
						name: "mobile",
						checkType: "isMobile",
						errorMsg: "请输入手机号"
					}, {
						name: "work_time",
						checkType: "isNumber",
						errorMsg: "请输入从业年份，例如：5",
						regType: 2
					}, {
						name: "city_id",
						checkType: "isNotNull",
						errorMsg: "请选择意向工作城市"
					}, {
						name: "type_id",
						checkType: "isNotNull",
						errorMsg: "请选择职业类型"
					}, {
						name: "station_icon",
						checkType: "isNotNull",
						errorMsg: "请选择岗位标签"
					}, {
						name: "free_fare_distance",
						checkType: "isFloatNum",
						errorMsg: "请输入公里数",
						regType: 2,
						maxNum: '',
						unit: '公里'
					}, {
						name: "address",
						checkType: "isNotNull",
						errorMsg: "请选择所在地址"
					}, {
						name: "text",
						checkType: "isNotNull",
						errorMsg: "请输入" + this.$t('action.attendantName') + "简介",
						regType: 2
					}, {
						name: "id_code",
						checkType: "isIdCard",
						errorMsg: "请输入您的身份证号码"
					},
					{
						name: "true_user_name",
						checkType: "isNotNull",
						errorMsg: "请输入您的真实姓名",
						regType: 2
					},
					{
						name: "id_card",
						checkType: "isNotNull",
						errorMsg: "请上传身份证人像面"
					},
					{
						name: "id_card_fan",
						checkType: "isNotNull",
						errorMsg: "请上传身份证国徽面"
					},
					{
						name: "id_card_people",
						checkType: "isNotNull",
						errorMsg: "请上传手持身份证照片"
					},
					{
						name: "license",
						checkType: "isNotNull",
						errorMsg: "请上传资格证书"
					},
					{
						name: "work_img",
						checkType: "isNotNull",
						errorMsg: "请上传工作形象照"
					},
					{
						name: "self_img",
						checkType: "isNotNull",
						errorMsg: "请上传"
					},
					{
						name: "order_num",
						checkType: "isNumber",
						errorMsg: "请输入虚拟订单量"
					},
				],
				have_user_id: false,
				lockTap: false,
				stationIndex: -1,
				stationList: [],
				personalityIndex: -1,
				personalityList: []
			}
		},
		computed: mapState({
			configInfo: state => state.config.configInfo,
		}),
		async onLoad(options) {
			let {
				id = 0,
					view = 0,
			} = options
			this.edit_base_info = view * 1 === 1 ? 0 : 1
			this.options = options
			let {
				store_auth = false
			} = this.$util.getPage(-1)
			this.store_auth = store_auth
			this.$util.showLoading()
			await this.initIndex()
			let {
				admin_id
			} = this.form
			let name = this.$t('action.attendantName')
			uni.setNavigationBarTitle({
				title: `${!this.edit_base_info ? '查看' : id ? '编辑' : '新增'}${name}`
			})
			// #ifdef H5 
			this.$jweixin.hideOptionMenu()
			// #endif
		},
		watch: {
			'form.industry_type'(intype) {
				let index = this.industryList.findIndex(item => {
					return item.id === intype
				})
				if (index == -1) return
				this.industryIndex = index
				this.industryInfo = this.industryList[index]
			},
			'form.birthday'(birthday) {
				if (birthday) {
					let arr = birthday.split('-')
					let month = arr[1]
					let day = arr[2]
					this.form.constellation = this.$util.getAstro(month, day)
				}
			}
		},
		methods: {
			...mapActions(['getConfigInfo', 'getUserInfo']),
			...mapMutations(['updateUserItem', 'updateMapItem']),
			async initIndex(refresh = false) {
				if (!this.configInfo.id || refresh) {
					await this.getConfigInfo()
				}
				let selfInd = this.rule.findIndex(item => {
					return item.name === 'self_img'
				})
				this.rule[selfInd].errorMsg = `请上传${this.$t('action.lifeText')}`
				this.$util.setNavigationBarColor({
					bg: this.primaryColor
				})
				let cur_time = new Date(Math.ceil(new Date().getTime()))
				this.toDay = this.$util.formatTime(cur_time, 'YY-M-D')
				this.toDayTime = this.$util.formatTime(cur_time, 'h:m')

				let [industry, carcashinfo] = await Promise.all([this.$api.technician.typeSelect(), this.$api.agent
					.adminCarCashInfo(), this.getCityList(), this.coachTypeSelect(), this.getCoachIconSelect()
				])
				this.industryList = industry
				this.faree_info = this.$util.pick(carcashinfo, ['free_fare_bear', 'free_fare_distance'])
				let {
					id = 0
				} = this.options
				if (!id) {
					let {
						industrytype
					} = this.configInfo.plugAuth
					if (industrytype !== 3) {
						let item = this.industryList.filter(aitem => {
							return aitem.type === industrytype
						})[0]
						this.form.industry_type = item.id
					}
					this.isLoad = true
					this.$util.hideAll()
					return
				}

				let data = await this.$api.agent.coachInfo({
					id
				})

				data.free_fare_distance = data.free_fare_distance == null ? '' : data.free_fare_distance
				if (!this.faree_info.free_fare_bear) {
					data.free_fare_distance = ''
				}

				let imgArr = ['id_card', 'license', 'self_img']
				imgArr.map(item => {
					data[item] = data[item] && data[item].length > 0 ? data[item].map(aitem => {
						return {
							path: aitem
						}
					}) : []
				})
				if (data.id_card && data.id_card.length > 1) {
					data.id_card_fan = [data.id_card[1]]
					data.id_card_people = [data.id_card[2]]
					data.id_card.splice(1, 3)
				}
				let imgArrs = ['work_img', 'video']
				imgArrs.map(item => {
					data[item] = data[item] && data[item].length > 0 ? [{
						path: data[item]
					}] : []
				})
				data.city_id = data.city_id || ''
				data.store_name = data.store && data.store.length > 0 ? this.$util.getItems(data.store,
					'title', '、') : ''
				data.store = data.store && data.store.length > 0 ? data.store.map(item => {
					return item.id
				}) : []
				data.type_id = data.type_id || ''
				data.height = data.height * 1 > 0 ? data.height : ''
				data.birthday = data.birthday * 1 > 0 ? this.$util.formatTime(data.birthday * 1000, 'YY-M-D') : ''
				if (!data.industry_info || data.industry_info == null) {
					data.industry_type = ''
				}
				for (let key in this.form) {
					this.form[key] = data[key]
				}
				if (data.industry_type) {
					this.industryInfo = data.industry_info
				}
				this.personalityIndex = this.personalityList.findIndex(item => {
					return item.id == data.personality_icon
				})
				this.cityIndex = this.cityList.findIndex(item => {
					return item.id == data.city_id
				})
				this.typeIndex = this.typeList.findIndex(item => {
					return item.id == data.type_id
				})
				if (this.typeIndex == -1) {
					this.form.type_id = ''
				}
				this.coach_status = data.status
				this.have_user_id = data.id && data.user_id
				this.fdd_agreement = data.fdd_agreement
				this.isLoad = true
				this.$util.hideAll()
				if (this.configInfo.plugAuth.industrytype == 3) {
					this.getStationIconSelect()
				}
			},
			initRefresh() {
				this.initIndex(true)
			},
			async getStationIconSelect() {
				let data = await this.$api.technician.stationIconSelect({
					industry_type: this.form.industry_type
				})
				this.stationList = data

				this.stationIndex = data.findIndex(item => {
					return item.id == this.form.station_icon
				})
				console.log(this.stationIndex, '========> this.stationIndex')
				if (this.stationIndex == -1) {
					this.form.station_icon = ''
					this.form.station_id = ''
				}
			},
			async getCoachIconSelect() {
				let data = await this.$api.technician.coachIconSelect()
				data.unshift({
					id: 0,
					title: `不关联个性标签`
				})
				this.personalityList = data
			},
			async getCityList() {
				let city = await this.$api.agent.getCity()
				this.$util.hideAll()
				this.cityList = city
				let cityIndex = city.length > 0 ? 0 : -1
				this.cityIndex = cityIndex
				this.form.city_id = cityIndex != -1 ? city[0].id : ''
			},
			async coachTypeSelect() {
				let {
					career = false
				} = this.configInfo.plugAuth
				if (career) {
					this.typeList = await this.$api.technician.coachTypeSelect()
				}
			},
			async toFddSign() {
				this.updateUserItem({
					key: 'fddExtsign',
					val: ''
				})
				let {
					viewpdf_url = ''
				} = this.fdd_agreement
				this.updateUserItem({
					key: 'fddExtsign',
					val: viewpdf_url
				})
				// #ifdef H5
				window.location.href = viewpdf_url
				// #endif
				// #ifndef H5
				this.$util.goUrl({
					url: `/userA/pages/common/web?url=fddExtsign`
				})
				// #endif
			},
			pickerChange(e, key) {
				let ind = e.target.value
				if (key === 'birthday') {
					let unix = this.$util.DateToUnix(ind)
					if (unix > new Date(Math.ceil(new Date().getTime())) / 1000) {
						this.$util.showToast({
							title: `不能选择未来时间哦`
						})
						return
					}
					this.form[key] = ind
					return
				}
				if (ind == -1) return
				this[`${key}Index`] = ind
				let {
					id
				} = this[`${key}List`][ind]
				if (key === 'industry') {
					this.form[`${key}_type`] = id
				} else if (key === 'personality') {
					this.form[`${key}_icon`] = id
				} else {
					this.form[`${key}_id`] = id
				}
				if (key === 'industry') {
					this.getStationIconSelect()
				}
			},
			imgUpload(e) {
				let {
					imagelist,
					imgtype
				} = e;
				this.form[imgtype] = imagelist;
			},
			toSetItem(index, key, key1) {
				let edit = this.toCheckEdit()
				if (!edit) return
				let {
					id
				} = this[key1][index]
				this.form[key] = id
			},
			toShowTime(key) {
				let edit = this.toCheckEdit()
				if (!edit) return
				this.showKey = key
				this.showTime = true
			},
			toCheckEdit() {
				let edit = true
				let {
					edit_base_info
				} = this
				if (!edit_base_info) {
					edit = false
				}
				return edit
			},
			onConfirm(val) {
				this.form[this.showKey] = val.result;
			},
			// 选择地区
			async toChooseLocation() {
				// #ifdef APP-PLUS
				if (plus.os.name == 'Android' && plus.navigator.checkPermission(
						'android.permission.ACCESS_FINE_LOCATION') ===
					'undetermined') {
					this.$refs.app_check_item.open()
				} else {
					this.toConfirmChooseLoca()
				}
				// #endif
				// #ifndef APP-PLUS
				this.toConfirmChooseLoca()
				// #endif
			},
			async toConfirmChooseLoca() {
				let edit = this.toCheckEdit()
				if (!edit) return

				// #ifdef MP-WEIXIN
				let privacyCheck = this.$refs.user_privacy.check()
				if (privacyCheck) {
					this.$refs.user_privacy.open()
					return
				}
				// #endif 

				let {
					lat,
					lng,
					address
				} = await this.$util.chooseLocation(1)
				if (!address) return
				this.form.lat = lat
				this.form.lng = lng
				this.form.address = address
			},
			toChooseUser() {
				let edit = this.toCheckEdit()
				if (!edit) return
				let {
					have_user_id
				} = this
				if (have_user_id) return
				this.$util.goUrl({
					url: `/agent/pages/technician/user`
				})
			},
			//表单验证
			validate(param) {
				let {
					plugAuth
				} = this.configInfo
				let {
					free_fare_bear,
					free_fare_distance
				} = this.faree_info
				let {
					industryInfo
				} = this
				let typeArr = ['height', 'weight', 'birthday']
				let validate = new this.$util.Validate();
				this.rule.map(item => {
					let {
						name,
					} = item
					if (typeArr.includes(name)) {
						if (industryInfo[name]) {
							validate.add(param[name], item)
						}
					} else if (name === 'work_time') {
						if (industryInfo.employment_years) {
							validate.add(param[name], item)
						}
					} else if (name === 'license') {
						if (industryInfo.qualification) {
							validate.add(param[name], item)
						}
					} else if (name == 'free_fare_distance') {
						if (param[name]) {
							if (free_fare_bear == 1) {
								item.maxNum = free_fare_distance
							}
							validate.add(param[name], item)
						}
					} else if (name == 'type_id') {
						if (plugAuth.career) {
							validate.add(param[name], item)
						}
					} else if (name == 'station_icon') {
						if (plugAuth.industrytype == 3) {
							validate.add(param[name], item)
						}
					} else {
						validate.add(param[name], item)
					}
				})
				let message = validate.start();
				return message;
			},
			async submit() {
				let param = this.$util.deepCopy(this.form)
				let arr = ['id_card', 'id_card_fan', 'id_card_people', 'work_img', 'video']
				arr.map(item => {
					param[item] = param[item]&&param[item].length > 0 ? param[item][0].path : ''
				})
				param.license = param.license && param.license.length > 0 ? param.license.map(item => {
					return item.path
				}) : []
				param.self_img = param.self_img.map(item => {
					return item.path
				})
				param.station_icon = param.station_id ? param.station_id : param.station_icon
				let msg = this.validate(param);
				if (msg) {
					this.$util.showToast({
						title: msg
					});
					return;
				}

				let {
					is_work: work = 0,
					start_time: start,
					end_time: end
				} = param
				if (work && (!start || !end)) {
					this.$util.showToast({
						title: !start ? '请选择开始时间' : '请选择结束时间'
					})
					return
				}

				param.free_fare_distance = param.free_fare_distance || 0
				param.birthday = param.birthday ? this.$util.DateToUnix(param.birthday) : ''
				param.id_card = [param.id_card, param.id_card_fan, param.id_card_people]
				delete param.id_card_fan
				delete param.id_card_people
				delete param.nickName
				delete param.city
				delete param.store_name
				delete param.station_id
				if (param.id) {
					delete param.admin_id
				}
				if (this.lockTap) return
				this.lockTap = true
				this.$util.showLoading()
				try {
					let {
						is_edit = 0
					} = this.options
					let methodModel = param.id ? 'coachUpdateAdmin' : 'coachApply'
					await this.$api.agent[methodModel](param)
					this.$util.hideAll()
					this.$util.showToast({
						title: `提交成功`
					})
					setTimeout(() => {
						this.$util.back()
						this.$util.goUrl({
							url: 1,
							openType: `navigateBack`
						})
					}, 2000)
				} catch (e) {
					setTimeout(() => {
						this.lockTap = false
						this.$util.hideAll()
					}, 2000)
				}

			}
		},
		filters: {
			handleStartEndTime(val, toDay) {
				let text = ''
				let {
					start_time,
					end_time
				} = val
				let start = `${toDay} ${start_time}`
				let end = `${toDay} ${end_time}`
				if (start_time && end_time && $util.DateToUnix(start) >= $util.DateToUnix(end)) {
					text = '次日'
				}
				return text
			}
		}
	}
</script>


<style lang="scss">
	.apply-pages {
		.apply-form {
			.item-text {
				width: 250rpx;
			}

			.item-text.tips {
				width: 200rpx;
			}
		}
	}

	.item-time {
		width: 50%;
	}
</style>